#include "operation.h"

#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>

void create_matrix(int*** left, int*** right, int*** result, int size)
{
	int i = 0;

	(*left) = (int** )malloc(size * sizeof(int* ));
	(*right) = (int** )malloc(size * sizeof(int* ));
	(*result) = (int** )malloc(size * sizeof(int* ));
	
	for (i = 0; i < size; i++)
	{
		(*left)[i]	= (int* )malloc(size * sizeof(int));
		(*right)[i] = (int* )malloc(size * sizeof(int));
		(*result)[i] = (int* )malloc(size * sizeof(int));
	}
}

void recycle_matrix(int** left, int** right, int** result, int size)
{
	int i = 0;

	for (i = 0; i < size; i++)
	{
		free(left[i]);	
		free(right[i]);	
		free(result[i]);	
	}

	free(left);
	free(right);
	free(result);
}

void initiate_matrix(int** left, int** right, int size, unsigned int seed)
{
	srandom(seed);

	int i = 0;
	int j = 0;

	for (i = 0; i < size; i++)
	{
		for (j = 0; j < size; j++)	
		{
			left[i][j] = random();	
			right[i][j] = random();	
		}
	}
}

int cmp_matrix(int** left, int** right, int size)
{
	int i = 0;
	int j = 0;

	for (i = 0; i < size; i++)
	{
		for (j = 0; j < size; j++)	
		{
			if (left[i][j] != right[i][j])
			{
				return 0;	
			}
		}
	}

	return 1;
}
